package com.thwj.project.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.thwj.common.annotation.Log;
import com.thwj.common.core.controller.BaseController;
import com.thwj.common.core.domain.AjaxResult;
import com.thwj.common.enums.BusinessType;
import java.util.Arrays;
import java.util.List;
import com.thwj.project.biz.domain.MerchantProduct;
import com.thwj.project.biz.service.IMerchantProductService;
import com.thwj.common.utils.poi.ExcelUtil;
import com.thwj.common.core.page.TableDataInfo;

/**
 * 商家产品套餐Controller
 *
 * @author generate
 * @date 2023-10-17
 */
@RestController
@RequestMapping("/biz/product")
public class MerchantProductController extends BaseController {
    @Autowired
    private IMerchantProductService merchantProductService;

/**
 * 查询商家产品套餐列表
 */
@PreAuthorize("@ss.hasPermi('biz:product:list')")
@GetMapping("/list")
    public TableDataInfo list(MerchantProduct merchantProduct) {
        startPage();
        List<MerchantProduct> list = merchantProductService.list(new QueryWrapper<>(merchantProduct));
        return getDataTable(list);
    }

    /**
     * 导出商家产品套餐列表
     */
    @PreAuthorize("@ss.hasPermi('biz:product:export')")
    @Log(title = "商家产品套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantProduct merchantProduct) {
        List<MerchantProduct> list = merchantProductService.list(new QueryWrapper<>(merchantProduct));
        ExcelUtil<MerchantProduct> util = new ExcelUtil<MerchantProduct>(MerchantProduct. class);
        util.exportExcel(response, list, "商家产品套餐数据");
    }

    /**
     * 获取商家产品套餐详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(merchantProductService.getById(id));
    }

    /**
     * 新增商家产品套餐
     */
    @PreAuthorize("@ss.hasPermi('biz:product:add')")
    @Log(title = "商家产品套餐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantProduct merchantProduct) {
        return toAjax(merchantProductService.save(merchantProduct));
    }

    /**
     * 修改商家产品套餐
     */
    @PreAuthorize("@ss.hasPermi('biz:product:edit')")
    @Log(title = "商家产品套餐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantProduct merchantProduct) {
        return toAjax(merchantProductService.updateById(merchantProduct));
    }

    /**
     * 删除商家产品套餐
     */
    @PreAuthorize("@ss.hasPermi('biz:product:remove')")
    @Log(title = "商家产品套餐", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(merchantProductService.removeByIds(Arrays.asList(ids)));
    }
}
